<template>
    <div class="hospital">
        <div class="left">
            <div class="breadcrumb">
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/' }">
                        <el-icon>
                            <HomeFilled />
                        </el-icon>
                    </el-breadcrumb-item>
                    <el-breadcrumb-item :to="`/hospital/register?hoscode=${$route.query.hoscode}`">医院信息</el-breadcrumb-item>
                    <el-breadcrumb-item :to="{ path: $route.path }">{{ $route.name }}</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="menu">
                <el-menu router :default-active="activeIndex" class="el-menu-vertical" @select="changeActive">
                    <el-menu-item index="/hospital/register">
                        <el-icon><icon-menu /></el-icon>
                        <span>预约挂号</span>
                    </el-menu-item>
                    <el-menu-item index="/hospital/detail">
                        <el-icon>
                            <document />
                        </el-icon>
                        <span>医院详情</span>
                    </el-menu-item>
                    <el-menu-item index="/hospital/notice">
                        <el-icon>
                            <setting />
                        </el-icon>
                        <span>预约须知</span>
                    </el-menu-item>
                    <el-menu-item index="/hospital/close">
                        <el-icon>
                            <InfoFilled />
                        </el-icon>
                        <span>停诊信息</span>
                    </el-menu-item>
                    <el-menu-item index="/hospital/search">
                        <el-icon>
                            <Search />
                        </el-icon>
                        <span>查询/取消</span>
                    </el-menu-item>
                </el-menu>
            </div>
        </div>
        <div class="content">
            <RouterView />
        </div>
    </div>
</template>

<script setup lang="ts">
import useDetailStore from '@/store/modules/hispitalDetail';
import {
    Document,
    HomeFilled,
    Menu as IconMenu,
    InfoFilled,
    Search,
    Setting,
} from '@element-plus/icons-vue'
import { computed, onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';

let detailStore = useDetailStore()
let $route = useRoute()
let $router = useRouter()
onMounted(() => {
    detailStore.getHospitalDetail($route.query.hoscode as string)
    detailStore.getDepartment($route.query.hoscode as string)
})
const changeActive = (index: string) => {
    $router.push({ path: index, query: { hoscode:$route.query.hoscode } })
}

let activeIndex = computed(() => {
    if ($route.path === '/hospital/register_step1' ||$route.path === '/hospital/register_step2') {
        return '/hospital/register';
    }
    return $route.path; 
})
</script>

<style scoped lang="scss">
.hospital {
    display: flex;

    .breadcrumb {
        padding-bottom: 20px;
    }

    .left {
        flex: 3;
        display: flex;
        flex-direction: column;
        align-items: center;
        position: sticky;
        height: 40vh;
        top: 6.5em;

        .el-menu {
            border: none;
        }
    }

    .content {
        flex: 10;
        margin-top: 50px;
        margin-left: 30px;
        z-index: 1;
    }
}

@media screen and (max-width:800px) {
    .hospital {
        .left {
            flex: 5;
        }
    }
}
</style>